import request from "@/utils/request";
export default {
    namespaced: true,
    state: {
        goodsArr: [],
        num: 1,
        goodsState: {}
    },
    actions: {

    },
    mutations: {
        getGoodsData(state, id) {
            request.post('/product/selectProductPage', {}).then(res => {
                if (res.code == 20000) {

                    state.goodsArr = res.data.list.map(item => ({
                        ...item,
                        price: item.price.toFixed(2)
                    }));
                    state.goodsState = state.goodsArr.find(item => item.id == id)
                }
            })
        },

        numChange(state, num) {
            state.num = num
        },
        goodsMutation(state, id) {
            state.goodsArr.find(item => {
                if (item.id = id) {
                    state.goods = item
                }
            })
        }
    },
    getters: {

    }
}